//package com.spider.im.chat.dao;
//
//import com.spider.im.chat.model.User;
//import com.spider.im.chat.utils.DatabaseManager;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import java.sql.*;
//
//public class UserDAO {
//    private static final Logger logger = LoggerFactory.getLogger(UserDAO.class);
//    // 添加用户
//    public boolean addUser(User user) {
//        String sql = "INSERT INTO chat_users (username, password, phone_number, wechat_number, remarks) VALUES (?, ?, ?, ?, ?)";
//        try (Connection conn = DatabaseManager.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql)) {
//            stmt.setString(1, user.getUsername());
//            stmt.setString(2, user.getPassword());
//            stmt.setString(3, user.getPhoneNumber());
//            stmt.setString(4, user.getWechatNumber());
//            stmt.setString(5, user.getRemarks());
//            int rowsAffected = stmt.executeUpdate();
//            return rowsAffected > 0;
//        } catch (SQLException e) {
//            logger.error("Error adding user: {}", e.getMessage());
//            return false;
//        }
//    }
//
//    // 查询用户
//    public User getUser(String username) {
//        String sql = "SELECT * FROM chat_users WHERE username = ?";
//        try (Connection conn = DatabaseManager.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql)) {
//            stmt.setString(1, username);
//            ResultSet rs = stmt.executeQuery();
//            if (rs.next()) {
//                return new User(
//                        rs.getString("username"),
//                        rs.getString("password"),
//                        rs.getString("phone_number"),
//                        rs.getString("wechat_number"),
//                        rs.getString("remarks")
//                );
//            }
//            return null;
//        } catch (SQLException e) {
//            logger.error("Error getting user: {}", e.getMessage());
//            return null;
//        }
//    }
//
//    // 更新用户信息
//    public boolean updateUser(User user) {
//        String sql = "UPDATE chat_users SET password = ?, phone_number = ?, wechat_number = ?, remarks = ? WHERE username = ?";
//        try (Connection conn = DatabaseManager.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql)) {
//            stmt.setString(1, user.getPassword());
//            stmt.setString(2, user.getPhoneNumber());
//            stmt.setString(3, user.getWechatNumber());
//            stmt.setString(4, user.getRemarks());
//            stmt.setString(5, user.getUsername());
//            int rowsAffected = stmt.executeUpdate();
//            return rowsAffected > 0;
//        } catch (SQLException e) {
//            logger.error("Error updating user: {}", e.getMessage());
//            return false;
//        }
//    }
//
//    // 删除用户
//    public boolean deleteUser(String username) {
//        String sql = "DELETE FROM chat_users WHERE username = ?";
//        try (Connection conn = DatabaseManager.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql)) {
//            stmt.setString(1, username);
//            int rowsAffected = stmt.executeUpdate();
//            return rowsAffected > 0;
//        } catch (SQLException e) {
//            logger.error("Error deleting user: {}", e.getMessage());
//            return false;
//        }
//    }
//
//    // 添加实名认证记录
//    public boolean addVerification(User user) {
//        String sql = "INSERT INTO chat_user_verification (user_id, real_name, id_card_number, status) VALUES (?, ?, ?, ?)";
//        try (Connection conn = DatabaseManager.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
//            // 获取用户ID
//            User existingUser = getUser(user.getUsername());
//            if (existingUser == null) {
//                return false; // 用户不存在
//            }
//            stmt.setLong(1, existingUser.getId());
//            stmt.setString(2, user.getRealName());
//            stmt.setString(3, user.getIdCardNumber());
//            stmt.setString(4, "PENDING"); // 初始状态为待审核
//            int rowsAffected = stmt.executeUpdate();
//            return rowsAffected > 0;
//        } catch (SQLException e) {
//            logger.error("Error adding verification: {}", e.getMessage());
//            return false;
//        }
//    }
//
//    // 查询实名认证状态
//    public String getVerificationStatus(String username) {
//        String sql = "SELECT status FROM chat_user_verification WHERE user_id = (SELECT id FROM users WHERE username = ?)";
//        try (Connection conn = DatabaseManager.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql)) {
//            stmt.setString(1, username);
//            ResultSet rs = stmt.executeQuery();
//            if (rs.next()) {
//                return rs.getString("status");
//            }
//            return "NOT_VERIFIED"; // 如果没有实名认证记录，返回未认证
//        } catch (SQLException e) {
//            logger.error("Error getting verification status: {}", e.getMessage());
//            return "ERROR";
//        }
//    }
//}
